package network.step3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.DataBindingException;

public class SimpleClient3 {
	public static void main(String[] args) throws IOException {

		Socket socket = null;
		PrintWriter out = null;
		BufferedReader br = null;
		BufferedReader k = null;

		try {
			socket = new Socket("127.0.0.1", 5000);
			System.out.println("========== 연결 완료 ==============");

			System.out.println("========== 원하는 글을 입력하세요. ==============");
			k = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(socket.getOutputStream(), true);
			br = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));

			String str = k.readLine();
			while (str != null) {
				out.println(str);
				//System.out.println(br.readLine());
				str = k.readLine();
			}

		} finally {
			//소캣을 마지막에 닫아라.
			if (out != null)
				out.close();
			if (br != null)
				br.close();
			if (k != null)
				k.close();
			if (socket != null)
				socket.close();
		}
	}

}
